/**
 * @version      BOSSCMS-Free
 * @trademark    BOSSCMS
 * @copyright    Copyright © by BOSSCMS-Free (https://www.bosscms.net/) 保留所有权利
 * @license      https://gitee.com/Greenpeas/BOSSCMS/license/ 和 https://www.bosscms.net/freelicense/
 * @link         https://www.bosscms.net/
 * @author       温州软界网络技术有限公司
**/
$(document).ready(function(e){
	if($G['func'] == 'edit'){
		$(document).on('change','code.param textarea[name=tag]',function(){
			$('code.tag ul li').removeClass('on');
			txtval = $(this).val();
			if(txtval){
				txtval = JSON.parse(txtval);
				for(i in txtval){
					$('code.tag ul li[value="'+txtval[i]+'"]').addClass('on');
				}
			}
		});
		$('code.tag div>a').click(function(){
			obj = {
				type: $.request('type')?$.request('type'):(type?type:null)
			};
			if(obj.type){
				$('code.tag>ul').remove();
				$.get($.mpf('tag','tag','select',obj),function(data){
					html='<ul>';
					data = JSON.parse(data);
					for(i in data){
						html+='<li value="'+$.quotesFilter(data[i].title)+'">'+data[i].title+'</li>';
					}
					html+='</ul>';
					$('code.tag').append(html);
					$('code.param textarea[name=tag]').change();
				});
			}
		});
		$(document).on('click','code.tag ul li',function(){
			if(!$(this).hasClass('on')){
				param = $('textarea[name=tag]').parents('code.param');
				param.find('ins input').val($(this).attr('value'));
				param.find('ins i.fa-plus').click();
			}
		});
		$('input[name="recommend[]"][value="j"]').change(function(){
			if($(this).prop('checked')){
				$('dl[link]').removeAttr('hide').find('input').attr('required','required');
			}else{
				$('dl[link]').attr('hide','hide').find('input').removeAttr('required');
			}
		});
		if(!$.request('type')){
			$('textarea[name="items"]').change(function(){
				items = $(this).val();
				if(models[items] != type){
					window.location.href = $.params(window.location.href,'items',items);
				}
			});
		}
	}
	if($G['func'] == 'init'){
		$('section.main.table .head button').click(function(){
			url = window.location.href.replace(/#.*$/,'');
			if(items = $('section.main.table .head textarea[name="items"]').val()){
				url = $.params(url,'items',items);
				url = $.params(url,'type',models[items]);
			}
			url = $.params(url,'keyword',(keyword=$('section.main.table .head input[name="keyword"]').val())?keyword:null);
			if(url != window.location.href.replace(/#.*$/,'')){
				window.location.href = url;
			}
		});
	}
});